<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>地理位置设置</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link href="../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../css/mui.poppicker.css" rel="stylesheet" />
		<!--App自定义的css-->
		<!-- <link rel="stylesheet" type="text/css" href="../css/app.css" /> -->
		<style>
			h5 {
				margin: 5px 7px;
			}
			.mui-input-row .mui-btn {
			    line-height: 1.1;
			    float: right;
			    width:65%;
			    padding: 10px 15px;
			}
		</style>
		<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">餐厅位置设置</h1>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded" style="margin: 5px;">
				
				<form class="mui-input-group" id="fmInput">
					<div class="mui-input-row">
						<label>经度:</label>
						<input type="text" id="JD"/>
					</div>
					<div class="mui-input-row">
						<label>纬度:</label>
						<input type="text"  id="WD"/>
					</div>
					
					<div class="mui-input-row" style="margin: 10px 5px;height:380px">
						
						<div id="container" 
						    style="
						        margin-top:10px; 
						        width: '90%'; 
						        height: 500px; 
						        border: 1px solid gray;
						        overflow:hidden;">
						</div>
						
					</div>
					
					
					<div class="mui-button-row">
						<button type="button" id="butOk" class="mui-btn mui-btn-primary" >确认</button>&nbsp;&nbsp;
						<button type="button" class="mui-btn mui-btn-danger" id="butCancel">取消</button>
					</div>
					
				</form>
				
				
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/tools.js"></script>
		<script src="gps.js"></script>
		
		<script>
			var strDefCity = "北京";
			if(g_jsonData.getData("curCity") != null && g_jsonData.getData("curCity") != undefined)
			{
				strDefCity = g_jsonData.getData("curCity");
				
				showMap("container",strDefCity,false,0,0,function(p_jd,p_wd)
				{
					document.getElementById("JD").value = p_jd; 
		    		document.getElementById("WD").value = p_wd;
				});
			}
			
			
			if (navigator.geolocation) 
			{
				debugger;
				console.log("h5 定位中");
				mui.toast('h5定位中...');
				navigator.geolocation.getCurrentPosition(function(position) 
				{
					var longitude = position.coords.longitude;
				    var latitude  = position.coords.latitude;
				    document.getElementById("JD").value = longitude; 
			    	document.getElementById("WD").value = latitude;
				    mui.toast('h5定位成功');
				    showMap("container",strDefCity,true,longitude,latitude,function(p_jd,p_wd)
					{
						document.getElementById("JD").value = p_jd; 
			    		document.getElementById("WD").value = p_wd;
					});
				}, 
				function(error) 
				{
					mui.toast('h5定失败；');
					
					showMap("container",strDefCity,false,0,0,function(p_jd,p_wd)
					{
						document.getElementById("JD").value = p_jd; 
			    		document.getElementById("WD").value = p_wd;
					});
				});
			}
			else
			{
				showMap("container",strDefCity,false,0,0,function(p_jd,p_wd)
				{
						document.getElementById("JD").value = p_jd; 
			    		document.getElementById("WD").value = p_wd;
				});
			}
									
			document.getElementById("butOk").addEventListener('tap', function(e) 
			{
				var main = plus.webview.getWebviewById(g_jsonData.getData("retUrl"));
				mui.fire(main,'gotmsg',{msg:'setgps',jd:document.getElementById("JD").value,wd:document.getElementById("WD").value});
				//mui.toast("back");
				mui.back();
			});
			
			document.getElementById("butCancel").addEventListener('tap', function(e) 
			{
				mui.back();
			});
		</script>
		
	</body>

</html>